import Storage from "web-storage-cache";
let localStorage:any;
if (typeof window !== 'undefined') {
	localStorage = new Storage();
}

export const set = <T>(key:string, value:T, expires=7):void => {
	if (typeof window !== 'undefined') {
    	localStorage.set(key, value, {exp : 3600 * 24 * expires})
	}
}

export const get = <T>(key:string):T|undefined => {
	if (typeof window !== 'undefined') {
    	return localStorage.get(key)
	}
	return undefined;
}

export const remove = (key:string):void => {
	if (typeof window !== 'undefined') {
    	localStorage.delete(key)
	}
}

export const clear = ():void => {
	if (typeof window !== 'undefined') {
		localStorage.clear();
		window.sessionStorage.clear();
	}
}
